import Vue from 'vue'
import _ from 'lodash'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import '@/plugins/hotent'
import i18n from '@/locale/index.js'
import '@/assets/css/element-custom.scss'
import '@/directive.js'
import HtSubmitButton from '@/components/common/HtSubmitButton.vue'
import HtDeleteButton from '@/components/common/HtDeleteButton.vue'
import HtLoadData from '@/components/common/HtLoadData.vue'
import VueUeditorWrap from 'vue-ueditor-wrap' //引入富文本组件
import VueCodeMirror from 'vue-codemirror'
import 'codemirror/lib/codemirror.css'
import 'codemirror/theme/base16-light.css'
import 'codemirror/mode/vue/vue'
import 'codemirror/mode/javascript/javascript'
import 'codemirror/mode/groovy/groovy'
import req from '@/request.js'
import 'jquery'
import deepmerge from 'deepmerge'
import validate from '@/validate.js'
import dict from '@/locale/validate/dict.js'
import VueAMap from 'vue-amap' //高德地图插件
import VueClipboard from 'vue-clipboard2' //复制内容到剪贴板
import 'moment/locale/zh-cn'
import fullscreen from 'vue-fullscreen'
//引入echart
import VueDND from 'awe-dnd'
//自定义标题组件
import CustomTitle from '@/components/common/CustomTitle.vue'
//自定义图标
import '@/customIcon/index'

Vue.directive('alterELDialogMarginTop'/*修改elementUI中el-dialog顶部的距离,传入值eg:{marginTop:'5vh'} */, {
  inserted(el, binding, vnode) {
    el.firstElementChild.style.marginTop = binding.value.marginTop
  }
})

Vue.config.productionTip = false
Vue.prototype.$http = req
Vue.config.productionTip = false
Vue.prototype.$http = req
/* 全局TableHeight */
Vue.prototype.$baseTableHeight = adjustHeight => {
  let height = window.innerHeight
  let paddingHeight = 270

  if ('number' == typeof adjustHeight) {
    height = height - paddingHeight + adjustHeight
  } else {
    height = height - paddingHeight
  }
  return height
}
Vue.use(ElementUI, {
  i18n: (key, value) => i18n.t(key, value),
  size: 'small'
})
//使用vue-codemirror组件
Vue.use(VueCodeMirror)
Vue.use(VueAMap)
Vue.use(VueClipboard)
Vue.use(fullscreen)
Vue.use(VueDND)

// 注册全局组件
Vue.component('HtSubmitButton', HtSubmitButton)
Vue.component('HtDeleteButton', HtDeleteButton)
Vue.component('HtLoadData', HtLoadData)
Vue.component('vue-ueditor-wrap', VueUeditorWrap)
Vue.component('CustomTitle', CustomTitle)

let app = new Vue({
  router,
  store,
  i18n,
  render: h => h(App)
}).$mount('#app')

export default app

let validateLocal = localStorage.getItem('lang')
let currentLocal = validateLocal || 'zh-CN'
app && app.$validator && app.$validator.localize(currentLocal)

Vue.prototype.$td = function(key, defaultMessage) {
  if (!key) {
    return defaultMessage
  }
  let result = i18n._t.apply(i18n, [
    key,
    i18n.locale,
    i18n._getMessages(),
    this
  ])
  return result === key && defaultMessage ? defaultMessage : result
}

if (app.$validator) {
  for (let rule in validate) {
    app.$validator.rules[rule] = validate[rule]
  }
  app.$validator.dictionary.container = deepmerge(
    dict,
    app.$validator.dictionary.container,
    {clone: true}
  )
}
